<?php

class ConexionBDSaving {

    private $link;

    public static function conectar() {
        if (!($link = mysqli_connect("localhost", "root", "root"))) {
            echo "Error conectando a la base de datos.";
            exit();
        }
        if (!mysqli_select_db($link, "senaempresa")) {
            echo "Error seleccionando la base de datos.";
            exit();
        }
        return $link;
    }

    public static function desconectar($link) {
        mysqli_close($link); //cierra la conexion
    }

    public static function liberarConsulta($result) {
        mysqli_free_result($result);
    }

    public static function registrar($link, $query) {
        //$result=mysql_query($query) or die('ERROR :'.mysql_error());
        $result = mysqli_query($link, $query);
        if ($result) {
            //ConexionBDSaving::liberarConsulta($result);
            return true;
        } else {
            //ConexionBDSaving::liberarConsulta($result);
            return false;
        }
    }

    public static function consultarTodo($link, $query) {
        $result = mysqli_query($link, $query) or die('ERROR :' . mysql_error());
        return $result;
    }

    public static function modificar($link, $query) {
        $result = mysqli_query($link, $query) or die('ERROR :' . mysql_error());
        return $result;
    }

    public static function eliminar($link, $query) {
        $result = mysqli_query($link, $query) or die('ERROR :' . mysqli_error());
        return $result;
    }

    public static function extraerNumeroRegistros($result) {
        $cantidadRegistros = mysqli_num_rows($result);
        return $cantidadRegistros;
    }

    public static function extraerFila($result) {
        $fila = mysqli_fetch_array($result);
        return $fila;
    }

    public static function extraerDatosLogin($link, $query) {
        $result = mysqli_query($link, $query) or die('ERROR :' . mysqli_error());

        if (mysqli_num_rows($result) > 0) {
            return true;
        } else {
            return false;
        }
        //return  $result;        
    }

}

?>